package com.jushu.storbox.view.resolve;

import java.io.File;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Stack;

import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.os.Message;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Toast;

import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.jushu.storbox.ActionLinkActivity;
import com.jushu.storbox.ActionShareActivity;
import com.jushu.storbox.R;
import com.jushu.storbox.ShareDriveApplication;
import com.jushu.storbox.actions.ActionShare;
import com.jushu.storbox.actions.AuthorizationAction;
import com.jushu.storbox.actions.DownloadAction;
import com.jushu.storbox.actions.FileAction;
import com.jushu.storbox.actions.FolderAction;
import com.jushu.storbox.actions.NodeAction;
import com.jushu.storbox.adapter.FileDisplayAdapter;
import com.jushu.storbox.callback.FileFolderInfoFileSizeSort;
import com.jushu.storbox.callback.FileFolderInfoNameSort;
import com.jushu.storbox.callback.FileFolderInfoTimeSort;
import com.jushu.storbox.constant.ClientConfig;
import com.jushu.storbox.constant.Constant;
import com.jushu.storbox.constant.IntentConstant;
import com.jushu.storbox.constant.MessageCode;
import com.jushu.storbox.constant.UiConstant;
import com.jushu.storbox.entities.FileFolderInfo;
import com.jushu.storbox.entities.FileType;
import com.jushu.storbox.handler.ClientExceptionRelateHandler;
import com.jushu.storbox.newfragment.argument.FileActionArgs;
import com.jushu.storbox.operation.group.FileItemMoreOperation;
import com.jushu.storbox.util.LogUtil;
import com.jushu.storbox.view.dialog.AbsPopupMenuDialog;
import com.jushu.storbox.view.dialog.DeleteFileDialog;
import com.jushu.storbox.view.dialog.DownloadDialogWithCheckWifi;
import com.jushu.storbox.view.dialog.PopupMenuWindow;
import com.jushu.storbox.view.dialog.RenameDialog;
import com.jushu.storbox.view.resolve.extend.IFileList;
import com.jushu.storbox.vo.PagedList;
import com.huawei.sharedrive.sdk.android.util.StringUtil;

public class TeamFileListResolve extends ListDisplayResolve<FileFolderInfo, FileItemMoreOperation<FileFolderInfo>, FileDisplayAdapter> {
	protected final static String TAG = FilleDisplayResolve.class.getSimpleName();

	private FileActionArgs folderArgument = null;
	private Stack<FileActionArgs> folderStack = new Stack<FileActionArgs>();
	private List<FileFolderInfo> datas = new ArrayList<FileFolderInfo>();
	private ProgressDialog waitDialog;

	FileItemMoreOperationImpl operation = new FileItemMoreOperationImpl();

	public TeamFileListResolve(Activity activity, FileActionArgs folderArgument, PullToRefreshListView listView) {
		super(activity);
		setFolderArgument(folderArgument);
		this.detailList = listView;
		waitDialog = new ProgressDialog(context);
		waitDialog.setMessage(context.getResources().getString(R.string.loading));
	}

	@Override
	protected FileDisplayAdapter initTemplateAdapter() {
		adapter = new FileDisplayAdapter(getActivity(), datas) {
			@Override
			protected Comparator<FileFolderInfo> getDefaultComparator() {
				Comparator<FileFolderInfo> result = null;
				SharedPreferences preference = context.getSharedPreferences(ClientConfig.settings, Context.MODE_APPEND);
				Editor edit = preference.edit();
				int temaSortCurrent = preference.getInt(UiConstant.TEMA_SUB_CURRENT_SORT, UiConstant.TEMA_SUB_SORT_BY_FILENAME);
				switch (temaSortCurrent & 0x000F) {
				case UiConstant.TEMA_SUB_SORT_BY_FILENAME: // 0X0001
					result = new FileFolderInfoNameSort(temaSortCurrent);
					break;
				case UiConstant.TEMA_SUB_SORT_BY_SIZE: // 0X0002
					result = new FileFolderInfoFileSizeSort(temaSortCurrent);
					break;
				case UiConstant.TEMA_SUB_SORT_BY_TIME: // 0X0003
					result = new FileFolderInfoTimeSort(temaSortCurrent);
					break;
				}
//				System.out.println("temaSortCurrent:" + Integer.toHexString(temaSortCurrent) );
				edit.putInt(UiConstant.TEMA_SUB_CURRENT_SORT, temaSortCurrent);
				edit.commit();
				return result;
			}};
		adapter.setPopWindow(operation.popWindow);
		return adapter;
	}

	@Override
	protected FileItemMoreOperation<FileFolderInfo> initAdapterOperation() {
		return operation;
	}

	@Override
	protected void refreshDataList() {
		if (folderArgument.getKeyWords() == null) {
			folderArgument.setPageIndex(Constant.FIRST_PAGE_INDEX);
			if (StringUtil.isNotBlank(folderArgument.getOwnerId())) {
				new FolderAction().openFolder(context, MessageCode.LOAD_FILE_LIST, folderArgument.getOwnerId(), folderArgument.getFolderId(),
						folderArgument.getFolderName(), Constant.FIRST_PAGE_INDEX, msgHandler);
			} else {
				LogUtil.e(TAG, "ownerId is null");
			}
		} else if (StringUtil.isNotBlank(folderArgument.getKeyWords())) {
			folderArgument.setPageIndex(Constant.FIRST_PAGE_INDEX);
			new FileAction().searchFileListFromServer(folderArgument.getOwnerId(), folderArgument.getKeyWords(), folderArgument.getPageIndex(), getActivity(),
					msgHandler);
		}
	}
 
	// setting and getting
	private Activity getActivity() {
		return (Activity) context;
	}

	public Stack<FileActionArgs> getFolderStack() {
		return folderStack;
	}

	public FileActionArgs getFolderArgument() {
		return folderArgument;
	}

	public void setFolderArgument(FileActionArgs folderArgument) {
		this.folderArgument = folderArgument;
	}

	@Override
	protected void clickItem(View clickView, int position, long id, FileFolderInfo info) {
		if (FileType.File.value() == info.getIsFile()) {
			openFile(position, info);
		} else {
			openFolder(position, info);
		}
	}

	private void openFile(int index, FileFolderInfo info) {
		new FileAction().openFile(context, info, msgHandler);
	}

	protected void openFolder(int index, FileFolderInfo info) {
		new FolderAction().openFolder(context, MessageCode.OPEN_FOLDER, info.getOwnerId(), info.getId(), info.getName(), Constant.FIRST_PAGE_INDEX, msgHandler);
	}

	public void openFolderWithWait(int index, FileFolderInfo info) {
		waitDialog.show();
		new FolderAction().openFolder(context, MessageCode.OPEN_FOLDER, info.getOwnerId(), info.getId(), info.getName(), Constant.FIRST_PAGE_INDEX, msgHandler);
	}
	
	private void doStartDownloadTask(FileFolderInfo info) {
		if (info.getIsFile() == FileType.File.value()) {
			new DownloadAction().downloadFile(context, info, true, msgHandler);
		} else if (info.getIsFile() == FileType.Folder.value()) {
			LogUtil.d(TAG, "download node is folder!");
			new DownloadAction().downloadFolder(context, info, true, msgHandler);
		} else {

		}
	}

	public void openParentFolder() {
		if (!getFolderStack().isEmpty()) {
			FileActionArgs parentArgument = getFolderStack().peek();
			if (Constant.ROOT_FOLDER_ID.equals(folderArgument.getFolderId())) {
				getFolderStack().pop();
				updateCurrentFolder(null, null, context.getString(R.string.team_space));
			} else {
				new FolderAction().openFolder(context, MessageCode.OPEN_PARENT_FOLDER, parentArgument.getOwnerId(), parentArgument.getFolderId(),
						parentArgument.getFolderName(), Constant.FIRST_PAGE_INDEX, msgHandler);
			}

		}
	}

	public void getMoreDataList() {
		new FolderAction().getMoreNodeListFromServer(context, folderArgument.getOwnerId(), folderArgument.getFolderId(), folderArgument.getPageIndex(),
				msgHandler);
	}

	public void loadDataList() {
		// folderArgument.setPageIndex(Constant.FIRST_PAGE_INDEX);
		// new FolderAction().openFolder(context, MessageCode.OPEN_FOLDER,
		// folderArgument.getOwnerId(), folderArgument.getFolderId(),
		// folderArgument.getFolderName(),
		// Constant.FIRST_PAGE_INDEX, msgHandler);

		if (folderArgument.getKeyWords() == null) {
			folderArgument.setPageIndex(Constant.FIRST_PAGE_INDEX);
			if (StringUtil.isNotBlank(folderArgument.getOwnerId())) {
				new FolderAction().openFolder(context, MessageCode.OPEN_FOLDER, folderArgument.getOwnerId(), folderArgument.getFolderId(),
						folderArgument.getFolderName(), Constant.FIRST_PAGE_INDEX, msgHandler);
			} else {
				LogUtil.e(TAG, "ownerId is null");
			}
		} else if (StringUtil.isNotBlank(folderArgument.getKeyWords())) {
			folderArgument.setPageIndex(Constant.FIRST_PAGE_INDEX);
			new FileAction().searchFileListFromServer(folderArgument.getOwnerId(), folderArgument.getKeyWords(), folderArgument.getPageIndex(), getActivity(),
					msgHandler);
		}
	}

	@Override
	public void binddingAdapter() {
		if (adapter != null) {
			adapter.cleanListDatasOnly();
		}
		super.binddingAdapter();
		// folderStack.push(folderArgument);
	}
	
	protected void updateCurrentFolder(String ownerId, String folderId, String folderName) {
	}
	
	ClientExceptionRelateHandler msgHandler = new ClientExceptionRelateHandler() {

		@SuppressWarnings("unchecked")
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case MessageCode.LOAD_FILE_LIST:
				handlerLoadFileList(msg);
				break;
			case MessageCode.OPEN_FOLDER:
				if(waitDialog.isShowing()){
					waitDialog.dismiss();
				}
				PagedList<FileFolderInfo> res = (PagedList<FileFolderInfo>) msg.obj;
				getFolderStack().push(getFolderArgument());
				setFolderArgument(new FileActionArgs());
				getFolderArgument().setOwnerId(res.getOwnerId());
				getFolderArgument().setFolderId(res.getPagedFolderId());
				getFolderArgument().setFolderName(res.getPagedFolderName());
				getFolderArgument().setPageIndex(Constant.FIRST_PAGE_INDEX);
				updateCurrentFolder(folderArgument.getOwnerId(), getFolderArgument().getFolderId(), getFolderArgument()
						.getFolderName());
				handlerLoadFileList(msg);
				break;
			case MessageCode.OPEN_PARENT_FOLDER:
				PagedList<FileFolderInfo> tmpRes = (PagedList<FileFolderInfo>) msg.obj;
				setFolderArgument(getFolderStack().pop());
				getFolderArgument().setOwnerId(tmpRes.getOwnerId());
				getFolderArgument().setFolderId(tmpRes.getPagedFolderId());
				getFolderArgument().setFolderName(tmpRes.getPagedFolderName());
				getFolderArgument().setPageIndex(Constant.FIRST_PAGE_INDEX);
				updateCurrentFolder(folderArgument.getOwnerId(), getFolderArgument().getFolderId(), getFolderArgument()
						.getFolderName());
				handlerLoadFileList(msg);
				break;
			case MessageCode.DELETE_FILE_SUCCESS:
				waitDialog.dismiss();
				adapter.removeData((FileFolderInfo) msg.obj);
				break;
			case MessageCode.RENAME_SUCCESS:
				waitDialog.dismiss();
				adapter.notifyDataSetChanged();
				break;
			case UiConstant.NODE_SEARCH_BY_KEYWORD:
				handlerLoadFileList(msg);
				waitDialog.dismiss();
				break;
			case MessageCode.MOVE_SUCCESS:
				adapter.removeData((FileFolderInfo) msg.obj);
				showToast(R.string.action_file_promit_move_source_success, Toast.LENGTH_SHORT);
				break;
			case MessageCode.TRANSFER_TO_MY_FILE_SUCCESS:
				showToast(R.string.action_transfer_success, Toast.LENGTH_SHORT);
				break;
			default:
				if (waitDialog.isShowing()) {
					waitDialog.dismiss();
				}
				super.handleMessage(msg);
			}
		}

		@SuppressWarnings("unchecked")
		private void handlerLoadFileList(Message msg) {
			PagedList<FileFolderInfo> pagedList = (PagedList<FileFolderInfo>) msg.obj;
			List<FileFolderInfo> pagedData = pagedList.getPagedList();
			onRefreshComplete();
			if (getFolderArgument().getPageIndex() == Constant.FIRST_PAGE_INDEX) {
				adapter.cleanListDatasOnly();
			}
			if (pagedData == null) {
				return;
			}
			adapter.addDatas(pagedData);
			getFolderArgument().incPageIndex();
			// unlock screen
		}

		@Override
		protected void onHandlerBefore(Message msg, String errorCode) {
			onRefreshComplete();
			super.onHandlerBefore(msg, errorCode);
		}

		@Override
		public Context getContext() {
			return getActivity();
		}
	};

	class FileItemMoreOperationImpl implements FileItemMoreOperation<FileFolderInfo> {
		public PopupMenuWindow popWindow;
		AbsPopupMenuDialog popMenu;
		View executeDownload;
		View cancelDownload;
		View syncDownload;

		int mIndex;
		FileFolderInfo mInfo;

		public FileItemMoreOperationImpl() {
			initPopWindow();
			initPopMenu();
		}

		private void initPopMenu() {
			popMenu = new AbsPopupMenuDialog(context, R.style.dialog_upload, R.layout.adapter_view_team_more_item) {
				public void onInflaterFinished(View contentView) {
					View transferTo = contentView.findViewById(R.id.adapter_team_file_transfer);
					transferTo.setOnClickListener(new View.OnClickListener() {
						public void onClick(View arg0) {
							LogUtil.i(TAG, "share team: " + mIndex);
							dismiss();
							onTransfer(mIndex, mInfo);
						}
					});
					View moveAction = contentView.findViewById(R.id.adapter_view_allfile_more_menu_move);
					moveAction.setOnClickListener(new View.OnClickListener() {
						public void onClick(View arg0) {
							LogUtil.i(TAG, "move: " + mIndex);
							dismiss();
							onMove(mIndex, mInfo);
						}
					});
					// View deleteAction =
					// contentView.findViewById(R.id.adapter_view_allfile_more_menu_delete);
					// deleteAction.setOnClickListener(new
					// View.OnClickListener() {
					// public void onClick(View arg0) {
					// LogUtil.i(TAG,"delete: "+mIndex);
					// dismiss();
					// onDelete(mIndex, mInfo);
					// }
					// });
					View renameAction = contentView.findViewById(R.id.adapter_view_allfile_more_menu_rename);
					renameAction.setOnClickListener(new View.OnClickListener() {
						public void onClick(View arg0) {
							LogUtil.i(TAG, "rename: " + mIndex);
							dismiss();
							onRename(mIndex, mInfo);
						}
					});
				}
			};
			WindowManager windowManager=getActivity().getWindowManager();
			Display display=windowManager.getDefaultDisplay();

			popMenu.setWindowWidth(display.getWidth());
			popMenu.setWindowPosition(Gravity.CENTER, 0, 0);

		}

		private void initPopWindow() {
			popWindow = new PopupMenuWindow(context, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, R.layout.adapter_team_file_window_more) {

				@Override
				protected void onInflaterFinished(View contentView) {
					executeDownload = contentView.findViewById(R.id.adapter_view_item_window_more_download_execute);
					cancelDownload = contentView.findViewById(R.id.adapter_view_item_window_more_download_cancel);
					syncDownload = contentView.findViewById(R.id.adapter_view_item_window_more_download_sync);
					View delAction = contentView.findViewById(R.id.adapter_view_item_window_more_del);
					delAction.setOnClickListener(new OnClickListener() {
						public void onClick(View v) {
							LogUtil.i(TAG, "delete: " + mIndex);
							dismiss();
							onDelete(mIndex, mInfo);
						}
					});
					View linkAction = contentView.findViewById(R.id.adapter_view_item_window_more_link);
					linkAction.setOnClickListener(new OnClickListener() {
						public void onClick(View arg0) {
							LogUtil.i(TAG, "link: " + mIndex);
							dismiss();
							if (mInfo != null) {
								onLinkItem(mIndex, mInfo);
							} else {
								LogUtil.e(TAG, "the data is null");
							}
						}
					});
					executeDownload.setOnClickListener(new OnClickListener() {
						public void onClick(View arg0) {
							LogUtil.i(TAG, "download: " + mIndex);
							dismiss();
							if (mInfo != null) {
								onDownloadItem(mIndex, mInfo);
							} else {
								LogUtil.e(TAG, "the data is null");
							}
						}
					});
					cancelDownload.setOnClickListener(new OnClickListener() {
						public void onClick(View paramView) {
							dismiss();
							if (mInfo != null) {
								new NodeAction().cleanNodeCatch(getActivity(), msgHandler, mInfo);
							} else {
								LogUtil.e(TAG, "the data is null");
							}
						}
					});
					syncDownload.setOnClickListener(new OnClickListener() {
						public void onClick(View paramView) {
							dismiss();
							if (mInfo != null) {
								new NodeAction().syncNode(getActivity(), msgHandler, mInfo);
							} else {
								LogUtil.e(TAG, "the data is null");
							}
						}
					});
					View moreAction = contentView.findViewById(R.id.adapter_view_item_window_more_moreaction);
					moreAction.setOnClickListener(new OnClickListener() {
						public void onClick(View view) {
							dismiss();
							popMenu.show();
						}
					});
				}
			};
		}

		@Override
		public void onItemMore(final int index, final FileFolderInfo Info) {
			this.mIndex = index;
			this.mInfo = Info;

			if (popWindow == null) {
				initPopWindow();
			}

			if (popMenu == null) {
				initPopMenu();
			}
			// set the view to default statues
			executeDownload.setVisibility(View.GONE);
			cancelDownload.setVisibility(View.GONE);
			syncDownload.setVisibility(View.GONE);

			// decade witch view to see
			switch (Info.getTransStatus()) {
			case Constant.DOWNLOAD_NON_UPDATE_DB:
				executeDownload.setVisibility(View.VISIBLE);
				break;
			case Constant.DOWNLOAD_ISRUNNING_UPDATE_DB:
				cancelDownload.setVisibility(View.VISIBLE);
				break;
			case Constant.DOWNLOAD_ISWAITING_UPDATE_DB:
				cancelDownload.setVisibility(View.VISIBLE);
				break;
			case Constant.DOWNLOAD_CANCEL_UPDATE_DB:
				executeDownload.setVisibility(View.VISIBLE);
				break;
			case Constant.DOWNLOAD_FAIL_UPDATE_DB:
				syncDownload.setVisibility(View.VISIBLE);
				break;
			case Constant.DOWNLOAD_SUCCESS_UPDATE_DB:
				switch (Info.getContentSyncState()) {
				case Constant.SYNC_STATUS_TRUE:
					cancelDownload.setVisibility(View.VISIBLE);
					break;
				case Constant.SYNC_STATUS_FALSE:
					syncDownload.setVisibility(View.VISIBLE);
					break;
				}
				break;
			}
		}

		public void onShareItem(int index, FileFolderInfo info) {
			if (new AuthorizationAction(getActivity()).checkIsRootAndNotify(getActivity(), msgHandler)) {
				return;
			}
			Intent intent = new Intent(getActivity(), ActionShareActivity.class);
			intent.putExtra(IntentConstant.INTENT_SHARE_DATA, info);
			getActivity().startActivity(intent);
		}

		public void onLinkItem(int index, FileFolderInfo info) {
			Intent linkIntent = new Intent();
			linkIntent.setClass(getActivity(), ActionLinkActivity.class);
			linkIntent.putExtra(IntentConstant.INTENT_LINK_DATA, info);
			getActivity().startActivityForResult(linkIntent, IntentConstant.INTENT_REQUEST_LINK);
		}

		public void onDownloadItem(int index, final FileFolderInfo info) {
			new DownloadDialogWithCheckWifi() {
				@Override
				protected void executeDownloadTask(FileFolderInfo info) {
					doStartDownloadTask(info);
					super.executeDownloadTask(info);
				}
			}.download(getActivity(), info);
		}

		public void onDelete(int index, final FileFolderInfo info) {
			new DeleteFileDialog().delete(getActivity(), ShareDriveApplication.getInstance().getWnerID(), info, msgHandler, waitDialog);
		}

		public void onRename(int index, FileFolderInfo info) {
			new RenameDialog().rename(getActivity(), info, waitDialog, msgHandler);
		}

	}

	public void onMove(int index, FileFolderInfo info) {
	}

	public void onTransfer(int index, FileFolderInfo info) {

	}

	public void execMove(Bundle bundle) {
		int sourceType = bundle.getInt(IntentConstant.INTENT_SOURCE_RESOURCE_TYPE);
		String targetResourceID = bundle.getString(IntentConstant.INTENT_TARGET_RESOURCE_ID);
		String targetResourceOwnerID = bundle.getString(IntentConstant.INTENT_TARGET_RESOURCE_OWNER);
		FileFolderInfo info = (FileFolderInfo) bundle.getSerializable(IntentConstant.INTENT_DATA_EXTENDS_1);
		if (StringUtil.isNotBlank(targetResourceID) && StringUtil.isNotBlank(targetResourceOwnerID)) {
			if (sourceType == FileType.File.value()) {
				new FileAction().moveFile(getActivity(), MessageCode.MOVE_SUCCESS, info, targetResourceID, targetResourceOwnerID, msgHandler);
			} else if (sourceType == FileType.Folder.value()) {
				new FolderAction().moveFolder(getActivity(), MessageCode.MOVE_SUCCESS, info, targetResourceID, targetResourceOwnerID, msgHandler);
			}
		} else {
			LogUtil.e(TAG, "some fileds is empty!");
		}
	}

	public void execCopyToSelf(Bundle bundle) {
		int sourceType = bundle.getInt(IntentConstant.INTENT_SOURCE_RESOURCE_TYPE);
		String sourceResourceID = bundle.getString(IntentConstant.INTENT_SOURCE_RESOURCE_ID);
		String sourceResourceOwnerID = bundle.getString(IntentConstant.INTENT_SOURCE_RESOURCE_OWNER);
		String targetResourceID = bundle.getString(IntentConstant.INTENT_TARGET_RESOURCE_ID);
		String targetResourceOwnerID = bundle.getString(IntentConstant.INTENT_TARGET_RESOURCE_OWNER);
		if (StringUtil.isNotBlank(sourceResourceID) && StringUtil.isNotBlank(sourceResourceOwnerID) && StringUtil.isNotBlank(targetResourceID)
				&& StringUtil.isNotBlank(targetResourceOwnerID)) {
			if (sourceType == FileType.File.value()) {
				new ActionShare().copyShareFile(getActivity(), MessageCode.TRANSFER_TO_MY_FILE_SUCCESS, sourceResourceOwnerID, sourceResourceID,
						targetResourceOwnerID, targetResourceID, msgHandler);
			} else if (sourceType == FileType.Folder.value()) {
				new ActionShare().copyShareFolder(getActivity(), MessageCode.TRANSFER_TO_MY_FILE_SUCCESS, sourceResourceOwnerID, sourceResourceID,
						targetResourceOwnerID, targetResourceID, msgHandler);
			}
		} else {
			LogUtil.e(TAG, "some fileds is empty!");
		}
	}

	public void sortByName(int sortType) {
		adapter.sort(new FileFolderInfoNameSort(sortType));
		writePreferenceForSort(UiConstant.TEMA_SUB_FILENAME_SORT, sortType);
	}

	public void sortByTime(int sortType) {
		adapter.sort(new FileFolderInfoTimeSort(sortType));
		writePreferenceForSort(UiConstant.TEMA_SUB_TIME_SORT, sortType);
	}

	public void sortBySize(int sortType) {
		adapter.sort(new FileFolderInfoFileSizeSort(sortType));
		writePreferenceForSort(UiConstant.TEMA_SUB_SIZE_SORT, sortType);
	}

	void writePreferenceForSort(String str, int sortType) {
		SharedPreferences preference = context.getSharedPreferences(ClientConfig.settings, Context.MODE_APPEND);
		Editor edit = preference.edit();
		edit.putInt(str, sortType);
		edit.putInt(UiConstant.TEMA_SUB_CURRENT_SORT, sortType);
		edit.commit();
	}
	
}
